'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	let table = event.table
	const collection = db.collection(table)
	const docList = await collection.limit(1).get();
	if (!docList.data || docList.data.length === 0) {
		return {
			status: -1,
			msg: '没拿到'+ table + '内的数据'
		}
	}
	const res = await collection.doc(docList.data[0]._id).update(event);
	if (res.updated === 1) {
		let result = Object.assign({},{
			_id : docList.data[0]._id 
		}, event)
		console.log("查看修改内容,",JSON.stringify(result));
		return {
			status: 0,
			msg: `修改成功${JSON.stringify(result)}`
		}
	}else  {
		return {
			status: -1,
			msg: '没拿到'+ table + '内的数据'
		}
	}
}
